package com.nowar.data.frame.util;

import com.nowar.common.exception.BBException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 获取RoutingKey
 *
 * @Author: 谢无殇。
 * @Date : 2023-01-16 22:52
 */
public class RoutingKeyUtil {

    public static String getKeyByShardingTable(String uid) {
        return String.valueOf(getNumberBy6(uid));
    }

    public static String getKeyByShardingJdbc(String uid) {
        return String.valueOf(getNumberBy2(uid));
    }


    public static Long getNumberBy2(String uid) {
        try {
            return Long.valueOf(uid) % 1000 / 2;
        } catch (NumberFormatException e) {
            throw new BBException("数据转换异常");
        }
    }

    public static Long getNumberBy6(String uid) {
        try {
            return Long.valueOf(uid) % 1000 / 6;
        } catch (NumberFormatException e) {
            throw new BBException("数据转换异常");
        }
    }

}
